package com.boot.mall.coupon.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boot.mall.coupon.entity.SeckillPromotionEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boot.common.utils.PageUtils;
import com.boot.common.utils.Query;

import com.boot.mall.coupon.dao.SeckillSkuRelationDao;
import com.boot.mall.coupon.entity.SeckillSkuRelationEntity;
import com.boot.mall.coupon.service.SeckillSkuRelationService;
import org.springframework.util.StringUtils;


@Service("seckillSkuRelationService")
public class SeckillSkuRelationServiceImpl extends ServiceImpl<SeckillSkuRelationDao, SeckillSkuRelationEntity> implements SeckillSkuRelationService {


    @Override
    public PageUtils pageSeckill(Map<String, Object> params) {
        // 获取参数
        String curr = (String) params.get("page");
        long current = 1;
        if (curr != null) {
            current = Integer.parseInt(curr);
        }
        long limit = 1;
        String limitStr = (String) params.get("limit");
        if (limitStr != null) {
            limit = Integer.parseInt(limitStr);
        }
        String sessionId = (String) params.get("promotionSessionId");
        QueryWrapper<SeckillSkuRelationEntity> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(sessionId)){
            wrapper.eq("promotion_session_id",sessionId);
        }
        Page<SeckillSkuRelationEntity> page = new Page<>(current, limit);
        baseMapper.selectPage(page,wrapper);
        PageUtils pageUtils = new PageUtils(page.getRecords(),(int)page.getTotal(),(int)limit,(int)current);
        return pageUtils;
    }
}